<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>redmoonid初始化</title>
  <link type="text/css" rel="stylesheet" th:href="@{${skinPath} + '/css.css'}"/>
  <script th:src="@{/inc/common.js}"></script>
  <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
  <link rel="stylesheet" th:href="@{/js/layui/css/layui.css}" media="all">
  <script th:src="@{/js/jquery-3.7.1.min.js}" type="text/javascript"></script>
  <script th:src="@{/js/jquery-alerts/cws.alerts.js}" type="text/javascript"></script>
  <link th:href="@{/js/jquery-alerts/jquery.alerts.css}" rel="stylesheet" type="text/css" media="screen"/>
</head>
<body>
<table cellSpacing="0" cellPadding="0" width="100%">
  <tbody>
  <tr>
    <td class="tdStyle_1">自增长ID初始化</td>
  </tr>
  </tbody>
</table>

<form name="form1" id="form1" method="get" action="?op=start" style="margin-top: 10px">
  <input type="hidden" name="op" value="start"/>
  <input type="hidden" name="formName" value=""/>
  <input type="hidden" name="nowId" value=""/>
  <table class="tabStyle_1 percent80">

    <tr>
      <td class=tabStyle_1_title width="20%">表名称</td>
      <td class=tabStyle_1_title width="20%">idType</td>
      <td class=tabStyle_1_title width="20%">当前表中最大id</td>
      <td class=tabStyle_1_title width="20%">自增长id</td>
      <td class=tabStyle_1_title width="20%">
        <input type="button" value="上一步" class="btn btn-default" onclick="window.location.href='tools'"/>&nbsp;&nbsp;
        <input type="button" class="btn btn-default" onclick="allTable()" value="初始化全部表"/></td>
    </tr>

    <tr th:each="ti: ${tInfo}">
      <td><span th:text="${ti.tName}"></span>
        <input type="hidden" th:id="'tname'+${ti.k}" th:value="${ti.tName}"/>
      </td>
      <td th:text="${ti.k}"></td>
      <td th:text="${ti.mid}" th:style="${ti.style}"></td>
      <td>
        <input type="text" th:id="'nid'+${ti.k}" th:value="${ti.nid}"/>
      </td>
      <td align="center">
        <input type="button" th:onclick="|csh(${ti.k})|" class="btn btn-default" value="初始化"/>
        &nbsp;&nbsp;&nbsp;&nbsp;<input type="button" th:onclick="|xg(${ti.k})|" class="btn btn-default" value="修改"/>
      </td>
    </tr>

  </table>
</form>
</body>
<script th:inline="javascript">
  function allTable() {
    var formData = { tableName: "all" };
    layer.confirm('您确定要初始化全部表么？', {icon: 3, title: '提示'}, function (index) {
      layer.close();
      $.ajax({
        type: "post",
        url: "initAllTable",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(formData), // 发送JSON字符串
        dataType: "json",
        beforeSend: function (XMLHttpRequest) {
          layer.closeAll('loading');
        },
        success: function (data, status) {
          layer.msg(data.msg, {
            offset: '6px'
          });
        },
        complete: function (XMLHttpRequest, status) {
          layer.closeAll('loading');
        },
        error: function (XMLHttpRequest, textStatus) {
          // 请求出错处理
          alert(XMLHttpRequest.responseText);
        }
      });
    });
  }

  function csh(k) {
    var formData = { tableName: $("#tname" + k).val() };
    layer.confirm('您确定要初始化么？', {icon: 3, title: '提示'}, function (index) {
      layer.close();
      $.ajax({
        type: "post",
        url: "initTable",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(formData),
        dataType: "html",
        beforeSend: function (XMLHttpRequest) {
          layer.closeAll('loading');
        },
        success: function (data, status) {
          data = $.parseJSON(data);
          layer.msg(data.msg, {
            offset: '6px'
          });
        },
        complete: function (XMLHttpRequest, status) {
          layer.closeAll('loading');
        },
        error: function (XMLHttpRequest, textStatus) {
          // 请求出错处理
          alert(XMLHttpRequest.responseText);
        }
      });
    });
  }

  function xg(k) {
    var formData = { tableName: $("#tname" + k).val(), tableId: $("#nid" + k).val() };
    layer.confirm('您确定要修改么？', {icon: 3, title: '提示'}, function (index) {
      layer.close();
      $.ajax({
        type: "post",
        url: "editTable",
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify(formData),
        dataType: "json",
        beforeSend: function (XMLHttpRequest) {
          layer.closeAll('loading');
        },
        success: function (data, status) {
          layer.msg(data.msg, {
            offset: '6px'
          });
        },
        complete: function (XMLHttpRequest, status) {
          layer.closeAll('loading');
        },
        error: function (XMLHttpRequest, textStatus) {
          // 请求出错处理
          alert(XMLHttpRequest.responseText);
        }
      });
    });
  }
</script>
</html>
